#pragma once
#include <vector>
#include <mutex>

//---------------------------------------------------------------------------
class ring
{
public:
	enum class ring_state : byte
	{
		active_group_0	= 0,
		active_group_1	= 1,
		active			= 2,
		inactive		= 3
	};

public:
	ring(){}
	virtual ~ring(){}

	void register_to_ring();

	template<typename _FairFunc>
	void operator()(_FairFunc& fair_section)
	{
		pre();

		// call fair section
		fair_section();

		post();
	}

protected:
	void pre(void);
	void post(void);

private:
	static __declspec(thread) int	_thread_index;
	std::vector<ring_state>			_states;
	ring_state						_ring_group		= ring_state::active_group_0;
	std::mutex						_registration_lock;
};
//---------------------------------------------------------------------------
